package cn.com.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import cn.com.util.DBUtil;
import cn.com.dao.info.LoginInf;

public class LoginImpl implements LoginInf{

	@Override
	public boolean validateByNameAndPwd(String username, String userpwd) {
		Connection conn = DBUtil. getConnection();
		PreparedStatement stm = null;
		ResultSet rs = null;
		String sql = "select * from userr where USER_NAME=? and USER_PASSWORD ";
		if (userpwd.equals("")) {
			sql += "is null";
		} else {
			sql += "=?";
		}
		boolean bool = false;
		try {
			stm = conn.prepareStatement(sql);
			stm.setString(1, username);
			if (!userpwd.equals("")) {
				stm.setString(2, userpwd);
			}
			rs = stm.executeQuery();
			bool = rs.next();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			DBUtil.free(conn,stm,rs);
		}
		return bool;
	}
}
